$(function(){
     window.thirdPartyFormAPI.registerEvent('afterFormFieldChange',function(event) {
                if ((event.display).indexOf("支持性文件")>=0) {
                     var formData=window.thirdPartyFormAPI.getFormData();
                     var sonJson=window.thirdPartyFormAPI.getFormData().formsons;
                     var att_tableName="";
                     var att_dateName="";
                     var nowRecordId=event.recordId;
                     var formmainName=window.thirdPartyFormAPI.getFormData().formData.tableInfo.formmain.tableName;
                     if(event.formType=="formmain"){
                            var dateCode="";
                            var mainJson=formData.formmains[formmainName];
                            for(var attCode in mainJson){
                                var dateName="支持文件上传时间"+event.display.substring(event.display.length-1);
                                if(mainJson[attCode].display==dateName){
                                    dateCode=mainJson[attCode].id;
                                }
                            }
                            if(dateCode != ""){
                             //回传表单信息
                               	var _fv_flag={
                               	            "tableName" :formmainName,
        	                                "tableCategory" : "formmain",  
        	                                "updateData" : {}
        	                    };
        	                     //更新附件信息，附件删除只允许一个，删除多余的附件
                                 	var _att_flag={"tableName" :att_tableName,
         	                                "tableCategory" : "formmain",  
         	                                "handlerMode":"delete",
         	                                "fieldName":event.id,
         	                                "deleteAttchmentData":[]
         	                        };  
        	                   if(event.value.length>1){//限制附件上传数量，只允许上传一个
                                    top.$.alert("每行只允许上传一个附件");
                                     setTimeout(function(){//删除多余的附件
                                         var attId=[];
                                         var attList=event.attachmentInfo.attachmentInfos;
                                         for(i=1;i<attList.length;i++){
                                         	attId.push(attList[i].id);
                                         }
                                         _att_flag.deleteAttchmentData=attId;
                                    	 window.thirdPartyFormAPI.backfillFormAttachment(_att_flag);
                                     },100);
                                } else if(event.value.length==1){//单个附件带入上传时间
                                    //更新日期控件时间
                                    var nowDate=seepDateToStr("yyyy-MM-dd HH:mm:ss",new Date());
                                    _fv_flag.updateData[dateCode]={"showValue2":nowDate,"value":nowDate};   
                                    if(mainJson[dateCode].value==""){
                                        window.thirdPartyFormAPI.backfillFormControlData(_fv_flag); 
                                      }
                                }else{
                                    //清除日期控件值
                                    _fv_flag.updateData[dateCode]={"showValue2":"","value":""};   
                                    window.thirdPartyFormAPI.backfillFormControlData(_fv_flag);  
                                } 
                            }    
                     }else{
                     //获取重复表表名和字段名
                     for (var val in sonJson) {
                                att_tableName=sonJson[val].tableName;
                                if((sonJson[val].display).indexOf("支持性文件")>=0){
                                    var att_records=sonJson[val].records[0].lists;
                                    for(var val2 in att_records){
                                          if((att_records[val2].display).indexOf("支持文件上传时间")>=0){
                                                att_dateName=val2;
                                          }
                                    }
                                }
                               if(att_dateName!=""){
                                //回传表单信息
                               	var _fv_flag={"tableName" :att_tableName,
        	                                "tableCategory" : "formson",  
        	                                "updateData" : {},
        	                                "updateRecordId":event.recordId
        	                        };
        	                    //更新附件信息，附件删除只允许一个，删除多余的附件
                                 	var _att_flag={"tableName" :att_tableName,
         	                                "tableCategory" : "formson",  
         	                                "updateRecordId":event.recordId,
         	                                "handlerMode":"delete",
         	                                "fieldName":event.id,
         	                                "deleteAttchmentData":[]
         	                        };  
        	                     if(event.value.length>1){//限制附件上传数量，只允许上传一个
                                    top.$.alert("每行只允许上传一个附件");
                                     setTimeout(function(){//删除多余的附件
                                         var att_records=sonJson[val].records;
                                         var att;
                                         for(var j=0;  j<att_records.length;j++){
                                                if(att_records[j].recordId==nowRecordId){
                                                	att=att_records[j].lists[_att_flag.fieldName];
                                                }
                                         }
                                         var attId=[];
                                         var attList=att.attachmentInfo.attachmentInfos;
                                         for(i=1;i<attList.length;i++){
                                         	attId.push(attList[i].id);
                                         }
                                         _att_flag.deleteAttchmentData=attId;
                                    	 window.thirdPartyFormAPI.backfillFormAttachment(_att_flag);
                                     },100);
                                } else if(event.value.length==1){//单个附件带入上传时间
                                     var date_records=sonJson[val].records;
                                     var datevalue;
                                     for(var j=0;  j<date_records.length;j++){
                                            if(date_records[j].recordId==event.recordId){
                                                datevalue=date_records[j].lists[att_dateName].value;
                                            }
                                     }
                                    //更新日期控件时间
                                    var nowDate=seepDateToStr("yyyy-MM-dd HH:mm:ss",new Date());
                                    _fv_flag.updateData[att_dateName]={"showValue2":nowDate,"value":nowDate};   
                                    if(datevalue==""){
                                        window.thirdPartyFormAPI.backfillFormControlData(_fv_flag); 
                                      }
                                }else{
                                    //清除日期控件值
                                    _fv_flag.updateData[att_dateName]={"showValue2":"","value":""};   
                                    window.thirdPartyFormAPI.backfillFormControlData(_fv_flag);  
                                } 
        	                     break;
                               }   
                       }
                    }
                }
            })

    //专家信息汇总---------------------------
    $("span").each(function(index,obj){
	   	 if(obj.innerText=="丨专家信息丨"){
	   		 $(obj).click(function(){
	   			 $(".formson-list__button").show();
	   		     $("div[title='专家信息数据汇总']").parent().hide();
	   		     if(parent.affairState =="-1"||parent.affairState =="1"){
		   			 $("div[title='专家信息数据汇总']").click();
	   		     }
	   		 });
	   	 }
       if(obj.innerText=="丨专家费汇总丨"){
            $(obj).click(function(){
               $(".formson-list__button").show();
               $("div[title='专家劳务费数据汇总']").parent().hide();
               if(parent.affairState =="-1"||parent.affairState =="1"){
                   $("div[title='专家劳务费数据汇总']").click();
               }
            })   		 
        }
       if(obj.innerText=="丨费用明细丨"){																		
            $(obj).click(function(){
               $(".formson-list__button").show();
               $("div[title='费用明细数据汇总']").parent().hide();
               if(parent.affairState =="-1"||parent.affairState =="1"){
                   $("div[title='费用明细数据汇总']").click();
               }
            })   		 
       }
	   	 
	    });	
	/*前台校验暂时关闭，改为发起前校验
	var isSeepForm=false;//是否是seep相关表单
	var formName=parent.$("#formtitle").val();//表单中文名
	var frontTable;//会议日程重复表名
	var startDateCode;
	var endDateCode;
	var nameCode;
	  $.ajax({
		url:'/seeyon/kkMeetingController.do?method=seepConfig&formName='+formName,
		async:false,
		cache:false,
		dataType:'json',
		success:function(result){
		  var dataAry=result;
		  for (var i = 0; i < dataAry.length; i++) {
			  var configFormName=dataAry[i].formName;
			  if(formName==configFormName){
				  isSeepForm=true;
				  frontTable=dataAry[i].frontTable;//会议日程重复表名
				  startDateCode=dataAry[i].startDateCode;
				  endDateCode=dataAry[i].endDateCode;
				  nameCode=dataAry[i].nameCode;
				  break;
			  }
		  }
		}
	 });
     if(isSeepForm){
    	
    	//会议时间重复校验-----------------------------------------------------------------------------------
        window.thirdPartyFormAPI.registerEvent('afterFormFieldChange',function(event) {
            if (event.display == '会议开始时间'||event.display == '会议结束时间'||event.display == '提供者编号') {
                    var _formData = window.thirdPartyFormAPI.getFormData();
                    //会议日程重复表数据
                    var meetingSon = _formData.formsons[frontTable].records;
                    //当前行会议开始时间
                    var nowRowStatDate;
                    //当前行会议结束时间
                    var nowRowEndDate;
                    //当前行会议提供者
                    var name;
                    for (var a = 0; a < meetingSon.length;a++) { 
                            if (meetingSon[a].recordId == event.recordId) {
                                 nowRowStatDate=meetingSon[a].lists[startDateCode].value;
                                 nowRowEndDate=meetingSon[a].lists[endDateCode].value;
                                 name=meetingSon[a].lists[nameCode].value;
                               }
                    }
                    //校验每一行数据
                    for (var a = 0; a < meetingSon.length;a++) {
                            if (meetingSon[a].recordId != event.recordId) {
                                //会议提供者人员名称相同
                                if(name==meetingSon[a].lists[nameCode].value){
                                    var startDate=meetingSon[a].lists[startDateCode].value;
                                    var endDate=meetingSon[a].lists[endDateCode].value;
                                    //会议时间重复校验
                                    if((nowRowStatDate>startDate&&nowRowStatDate<endDate)||(nowRowEndDate>startDate&&nowRowEndDate<endDate)){
                                        alert("该人员在该时间段内已有会议，不能重复参加！重复数据（"+name+","+nowRowStatDate+","+nowRowEndDate+"）");
                                        return;
                                    }
                                    if(nowRowStatDate<=startDate&&nowRowEndDate>=endDate){
                                    	alert("该人员在该时间段内已有会议，不能重复参加！重复数据（"+name+","+nowRowStatDate+","+nowRowEndDate+"）");
                                    	return;
                                    }
                                }
                               }
                    }
               }
   });
	  }
	  */
});
//日期转字符串
 var  seepDateToStr = function(formatStr, date){
        formatStr = arguments[0] || "yyyy-MM-dd HH:mm:ss";
        date = arguments[1] || new Date();
        var str = formatStr;   
        var Week = ['日','一','二','三','四','五','六'];  
        str=str.replace(/yyyy|YYYY/,date.getFullYear());   
        str=str.replace(/yy|YY/,(date.getYear() % 100)>9?(date.getYear() % 100).toString():'0' + (date.getYear() % 100));   
        str=str.replace(/MM/,date.getMonth()>9?(date.getMonth() + 1):'0' + (date.getMonth() + 1));   
        str=str.replace(/M/g,date.getMonth());   
        str=str.replace(/w|W/g,Week[date.getDay()]);   
      
        str=str.replace(/dd|DD/,date.getDate()>9?date.getDate().toString():'0' + date.getDate());   
        str=str.replace(/d|D/g,date.getDate());   
      
        str=str.replace(/hh|HH/,date.getHours()>9?date.getHours().toString():'0' + date.getHours());   
        str=str.replace(/h|H/g,date.getHours());   
        str=str.replace(/mm/,date.getMinutes()>9?date.getMinutes().toString():'0' + date.getMinutes());   
        str=str.replace(/m/g,date.getMinutes());   
      
        str=str.replace(/ss|SS/,date.getSeconds()>9?date.getSeconds().toString():'0' + date.getSeconds());   
        str=str.replace(/s|S/g,date.getSeconds());   
      
        return str;   
    }